/*     */ package com.cr.framework.web.exception;
/*     */ 
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.exception.DemoModeException;
/*     */ import com.cr.common.exception.ServiceException;
/*     */ import com.cr.common.utils.ServletUtils;
/*     */ import com.cr.common.utils.security.PermissionUtils;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.shiro.authz.AuthorizationException;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.validation.BindException;
/*     */ import org.springframework.validation.ObjectError;
/*     */ import org.springframework.web.HttpRequestMethodNotSupportedException;
/*     */ import org.springframework.web.bind.annotation.ExceptionHandler;
/*     */ import org.springframework.web.bind.annotation.RestControllerAdvice;
/*     */ import org.springframework.web.servlet.ModelAndView;
/*     */ 
/*     */ @RestControllerAdvice
/*     */ public class GlobalExceptionHandler {
/*  26 */   private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
/*     */   
/*     */   @ExceptionHandler({AuthorizationException.class})
/*     */   public Object handleAuthorizationException(AuthorizationException e, HttpServletRequest request) {
/*  34 */     String requestURI = request.getRequestURI();
/*  35 */     log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage());
/*  36 */     if (ServletUtils.isAjaxRequest(request))
/*  38 */       return AjaxResult.error(PermissionUtils.getMsg(e.getMessage())); 
/*  42 */     return new ModelAndView("error/unauth");
/*     */   }
/*     */   
/*     */   @ExceptionHandler({HttpRequestMethodNotSupportedException.class})
/*     */   public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request) {
/*  53 */     String requestURI = request.getRequestURI();
/*  54 */     log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
/*  55 */     return AjaxResult.error(e.getMessage());
/*     */   }
/*     */   
/*     */   @ExceptionHandler({RuntimeException.class})
/*     */   public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) {
/*  64 */     String requestURI = request.getRequestURI();
/*  65 */     log.error("请求地址'{}',发生未知异常.", requestURI, e);
/*  66 */     return AjaxResult.error(e.getMessage());
/*     */   }
/*     */   
/*     */   @ExceptionHandler({Exception.class})
/*     */   public AjaxResult handleException(Exception e, HttpServletRequest request) {
/*  75 */     String requestURI = request.getRequestURI();
/*  76 */     log.error("请求地址'{}',发生系统异常.", requestURI, e);
/*  77 */     return AjaxResult.error(e.getMessage());
/*     */   }
/*     */   
/*     */   @ExceptionHandler({ServiceException.class})
/*     */   public Object handleServiceException(ServiceException e, HttpServletRequest request) {
/*  86 */     log.error(e.getMessage(), (Throwable)e);
/*  87 */     if (ServletUtils.isAjaxRequest(request))
/*  89 */       return AjaxResult.error(e.getMessage()); 
/*  93 */     return new ModelAndView("error/service", "errorMessage", e.getMessage());
/*     */   }
/*     */   
/*     */   @ExceptionHandler({BindException.class})
/*     */   public AjaxResult handleBindException(BindException e) {
/* 103 */     log.error(e.getMessage(), (Throwable)e);
/* 104 */     String message = ((ObjectError)e.getAllErrors().get(0)).getDefaultMessage();
/* 105 */     return AjaxResult.error(message);
/*     */   }
/*     */   
/*     */   @ExceptionHandler({DemoModeException.class})
/*     */   public AjaxResult handleDemoModeException(DemoModeException e) {
/* 114 */     return AjaxResult.error("演示模式，不允许操作");
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-framework-4.7.0.jar!\com\cr\framework\web\exception\GlobalExceptionHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */